package com.zxl.common.exception;

import com.zxl.common.constant.ResponseStatusCode;
import lombok.Data;

/**
 * @author zxw
 * @date 2023/3/31
 */
@Data
public class BusinessException extends RuntimeException{

    public static final String VALUE_CAN_NOT_BE_EMPTY = "值不能为空";
    public static final String IT_ALREADY_EXISTS = "它已经存在";
    public static final String NOT_EQUAL = "值不相等";
    public static final String NOT_FIND = "未找到";

    private Integer code = ResponseStatusCode.ERROR.getCode();

    private Object data;


    public BusinessException() {
    }

    public BusinessException(ResponseStatusCode responseStatusCode) {
        super(responseStatusCode.getMessage());
        this.code = responseStatusCode.getCode();
    }

    public BusinessException(ResponseStatusCode responseStatusCode, String... args) {
        super(String.format(responseStatusCode.getMessage(), args));
        this.code = responseStatusCode.getCode();
    }

    public BusinessException(String message) {
        super(message);
    }

    public BusinessException(String name,String why) {
        super(name+" " +why);
    }

    public BusinessException(String name,Object value,String why) {
        super(name+"："+value + " " +why);
    }

    public BusinessException(String message, Throwable cause) {
        super(message, cause);
    }

    public BusinessException(Throwable cause) {
        super(cause);
    }

    public BusinessException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
        super(message, cause, enableSuppression, writableStackTrace);
    }

    public BusinessException(ResponseStatusCode responseStatusCode, Object data, String... args){
        super(String.format(responseStatusCode.getMessage(), args));
        this.code = responseStatusCode.getCode();
        this.data = data;
    }


    public static BusinessException NotBeEmpty(String message){
        return new BusinessException(message,VALUE_CAN_NOT_BE_EMPTY);
    }
}
